<template>
	<div>
		<div class="h2">活动评价列表</div>
		<div id="components-form-demo-advanced-search">
			<a-form class="ant-advanced-search-form home-form" :form="form" @submit="handleSearch">
				<a-row :gutter="24">

					<!-- <a-col :span="8">
						<a-form-item label="俱乐部">
							<template>
								<a-select v-decorator="['clubID']" showSearch optionFilterProp="children"
									style="width: 100%" :showArrow="false" @search="fetchClub"
									:filterOption="filterOption" placeholder="请输入关键字进行搜索" allowClear>
									<a-select-option v-for="(item, index) in ClubList" :key="item.ID">{{ item.Name }}
									</a-select-option>
								</a-select>
							</template>
						</a-form-item>
					</a-col> -->
					<a-col :span="8">
						<a-form-item label="活动名称"><a-input autocomplete="off" class="field-right" placeholder="请输入活动名称搜索" v-decorator="[`key`]" /></a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="添加人">
							<a-select showSearch allowClear optionFilterProp="children" placeholder="请输入学号进行搜索"
								style="width: 100%" v-decorator="[`addUserNo`]" @search="fetchUser"
								:filterOption="filterOption">
								<a-spin v-if="fetching" slot="notFoundContent" size="small" />
								<a-select-option v-for="(item, index) in userList" :key="item.UserNo">
									{{ item.UserNo }}&nbsp;|&nbsp;{{ item.Name }}
								</a-select-option>
							</a-select>
						</a-form-item>
					</a-col>
					<!-- <a-col :span="8">
						<a-form-item label="调用时间">
							<a-range-picker v-decorator="[`data`]" />
						</a-form-item>
					</a-col> -->
					<a-col :span="8">
						<a-form-item label="状态">
							<a-select v-decorator="[`state`]">
								<a-select-option v-for="(item, index) in stateList" :key="item.ID">{{ item.Name }}
								</a-select-option>
							</a-select>
						</a-form-item>
					</a-col>
					<a-col :span="8" style="margin-top:4px;">
						<a-button type="primary" html-type="submit" class="btn1">搜索</a-button>
						<a-button :style="{ marginLeft: '8px' }" @click="handleReset" class="btn2">重置</a-button>
					</a-col>
				</a-row>
			</a-form>
		</div>
		<div style="margin-top:20px;">
			<el-table :data="data" v-loading="loading" border :max-height="tableHeight" highlight-current-row
				style="width: 100%;">
				<el-table-column prop="ActivityName" label="活动名称" min-width="150"></el-table-column>
				<el-table-column prop="Content" label="评价内容" min-width="200" show-overflow-tooltip></el-table-column>
				<el-table-column prop="AddTime" label="评分类型" min-width="220">
					<template slot-scope="scope">
						<a-tag color="#108ee9" v-for="(item,index) in scope.row.ItemList" style="margin-bottom: 8px;">
							{{item.ItemName}}/{{item.Score}}分{{index!==scope.row.ItemList.length-1?'，':''}}
						</a-tag>
					</template>
				</el-table-column>
				<el-table-column prop="Title" label="添加人" min-width="150">
					<template slot-scope="scope">
						<a-tag color="#108ee9">{{ scope.row.AddUserNo }}/{{ scope.row.AddUserName }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column prop="AddTime" label="添加时间" min-width="200"></el-table-column>
				<el-table-column prop="ChargeUserNo" label="审批状态" min-width="160">
					<template slot-scope="scope">
						<a-tag
							:color="scope.row.State=='1'?'blue':scope.row.State=='2'?'green':scope.row.State=='3'?'red':''">
							{{scope.row.State=='1'?'待审核':scope.row.State=='2'?'审核通过':scope.row.State=='3'?'审核不通过':''}}
						</a-tag>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="120">
					<template slot-scope="scope">
						<!-- <i title="详情" class="iconfont icon-xiangqing" style="color: #1890FF;" @click="seeList(scope.row, 'detail')"></i> -->
						<i title="审批" v-if="scope.row.State==1" class="iconfont icon-shenpi" style="color: blue;"
							@click="applyHander(scope.row)"></i>
						<i title="删除" class="iconfont icon-delete" style="color: red;"
							@click="deleteList(scope.row)"></i>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:current-page="pagination.currentPage" :page-sizes="pagination.pageSizeOptions"
				:page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper"
				:total="pagination.total"></el-pagination>
		</div>
		<apply :isShow="false" :text="text" v-show="applyIf" @closeFun="closeFun"></apply>
	</div>
</template>

<script>
	import moment from 'moment';
	import Func from '@/utils/func';
	import apply from './apply';
	import {
		ManageActivityEvaluationDoGetPageList,
		GetActivityStateList,
		GetClubPageListCommon,
		GetUserList,
		ManageActivityEvaluationDoDelete
	} from '@/api/follow';
	const data = [];
	export default {
		components: {
			apply
		},
		data() {
			return {
				applyIf: false,
				data,
				form: this.$form.createForm(this, {
					name: 'advanced_search'
				}),
				pagination: {
					currentPage: 1,
					pageSize: this.global.pageSize,
					pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
					showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
				},
				addIf: false,
				text: {},
				visible: false,
				confirmLoading: false,
				itemId: '',
				departmentList: [],
				worklist: [],
				stateList: [{
						ID: '1',
						Name: '待审核'
					},
					{
						ID: '2',
						Name: '审核通过'
					},
					{
						ID: '3',
						Name: '审核不通过'
					}
				],
				loading: false,
				values: {},
				pages: {
					pageIndex: 1,
					pageSize: 20
				},
				tableHeight: parseFloat(window.innerHeight - 160),
				ActivityStateList: [],
				ClubList: [],
				tabkey: 1,
				userList: [],
				fetching: false,
			};
		},
		computed: {},
		created() {
			this.getList();
			// this.getOtherList()
		},
		mounted() {},
		methods: {
			async fetchUser(value) {
				this.fetching = true;
				let myReg = /^[^a-zA-Z]+$/;
				if (value && myReg.test(value) && value.length > 3) {
					let data = {};
					data.key = value;
					data.top = 20;
					let res = await GetUserList(data);
					this.fetching = false;
					this.userList = res.data.data;
				}
			},
			async fetchClub(value) {
				let myReg = /^[^a-zA-Z]+$/;
				if (value) {
					let data = {};
					data.key = value;
					let res = await GetClubPageListCommon(data);
					this.ClubList = res.data.data
				}
			},
			moment,
			tabChange(key) {
				this.tabkey = key
			},
			filterOption(input, option) {
				return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0;
			},
			async fetchUser(value) {
				this.fetching = true;
				let myReg = /^[^a-zA-Z]+$/;
				if (value && myReg.test(value) && value.length > 3) {
					let data = {};
					data.key = value;
					data.top = 20;
					let res = await GetUserList(data);
					this.fetching = false;
					this.userList = res.data.data;
				}
			},
			deleteList(text) {
				let that = this;
				this.$confirm({
					title: '提示',
					content: `您确定删除该评价吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {};
						data.id = text.ID;
						let res = await ManageActivityEvaluationDoDelete(data);
						if (res.data.code == 0) {
							that.getList();
							that.$message.success(res.data.msg);
						} else {
							that.$message.error(res.data.msg);
						}
					}
				});
			},
			async fetchClub(value) {
				let myReg = /^[^a-zA-Z]+$/;
				if (value) {
					let data = {};
					data.key = value;
					let res = await GetClubPageListCommon(data);
					this.ClubList = res.data.data
				}
			},
			handleSearch(e) {
				e.preventDefault();
				this.form.validateFields((error, values) => {
					this.pagination.currentPage = 1;
					console.log(values)
					if (values.data && values.data.length > 0) {
						values.transferStartTime = values.data[0].format('YYYY-MM-DD')
						values.transfeEndTime = values.data[1].format('YYYY-MM-DD')
					}
					this.values = values;
					this.getList();
				});
			},
			handleReset() {
				this.form.resetFields();
				this.values = {};
				this.getList();
			},
			handleSizeChange(val) {
				this.pagination.pageSize = val;
				this.getList();
			},
			handleCurrentChange(val) {
				this.pagination.currentPage = val;
				this.getList();
			},
			async getList() {
				this.loading = true;
				let data = {};
				if (this.values) {
					data = this.values;
				}
				data.activityID = this.$route.query.ID;
				// data.flowType = this.flowType;
				// data.state = this.state || this.values.state;
				data.pageIndex = this.pagination.currentPage;
				data.pageSize = this.pagination.pageSize;
				let res = await ManageActivityEvaluationDoGetPageList(data);
				this.loading = false;
				this.data = res.data.data;
				const pagination = {
					...this.pagination
				};
				pagination.total = res.data.pageInfo.TotalItemCount;
				this.pagination = pagination;
			},
			async getOtherList() {
				let res = await GetActivityStateList()
				this.ActivityStateList = res.data.data
			},
			addList() {
				this.text = {};
				this.addIf = !this.addIf;
			},

			seeList(text, name) {
				let path = 'ClueDetail'
				this.$router.push({
					name: path,
					query: {
						ID: text.ID,
						ActivityID: text.ActivityID
					}
				});
			},
			applyHander(item) {
				//this.$emit('applyHander', item)
				this.text = item
				this.applyIf = true
			},
			closeFun() {
				this.applyIf = false;
				this.getList()
			}
		}
	};
</script>

<style lang="less" scoped>
	/deep/.ant-form-item {
		display: flex;
		margin-bottom: 10px !important;

		/deep/.ant-form-item-label {
			width: 80px;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
			text-align: right;
		}

		/deep/.ant-form-item-control-wrapper {
			flex: 1;
		}
	}

	/deep/.ant-table-thead>tr>th,
	/deep/.ant-table-tbody>tr>td {
		padding: 5px;
	}

	/deep/.ant-table-pagination.ant-pagination {
		float: left;
		// display:none;
	}

	/deep/.ant-table-body tr th:first-child {
		display: none;
	}

	/deep/.ant-table-body tr td:first-child {
		display: none;
	}

	/deep/.el-table th.is-leaf {
		background: #fafafa;
	}

	/deep/.el-table td,
	/deep/.el-table th {
		padding: 5px;
	}

	/deep/.ant-table-tbody .ant-table-row-cell-break-word:nth-child(2) {
		position: relative;

		.con {
			position: absolute;
			top: 40px;
			left: 0px;
			z-index: 999;
			background: #fff;
			width: 96%;
			padding: 1% 2%;
		}
	}

	.option {
		margin-top: 10px;
		margin-bottom: 20px;
		overflow: hidden;
	}

	.option .btn {
		height: 36px;
		line-height: 36px;
		padding: 0 10px;
		float: left;
		background: #1890ff;
		color: #fff;
		margin-right: 10px;
		border-radius: 3px;
		cursor: pointer;
		border: none;
	}

	.foot {
		text-align: center;
		margin-top: 100px;
	}

	.el-pagination {
		margin-top: 10px;
	}
</style>
